﻿using System;

namespace LocalOverride.Fiddler.UrlMapping
{
    public class SingleFileMapping : IMapping
    {
        private readonly Uri url;
        private readonly string localPath;

        public SingleFileMapping(Uri url, string localPath)
        {
            this.url = url;
            this.localPath = localPath;
        }

        public bool Matches(Uri request)
        {
            var trimmedRequest = RemoveQueryString(request);
            return (trimmedRequest == url);
        }

        public MappingResult Map(Uri request)
        {
            return new MappingResult(localPath, false);
        }

        private Uri RemoveQueryString(Uri requestUri)
        {
            var uriWithoutQueryString = new Uri(requestUri.GetLeftPart(UriPartial.Path));
            return uriWithoutQueryString;
        }

    }
}